package cn.ds.assets.module.assets.dal.mysql.project;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.project.BaseProjectDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.project.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 项目 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseProjectMapper extends BaseMapperX<BaseProjectDO> {

    default PageResult<BaseProjectDO> selectPage(BaseProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseProjectDO>()
                .betweenIfPresent(BaseProjectDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(BaseProjectDO::getProjectName, reqVO.getProjectName())
                .inIfPresent(BaseProjectDO::getId,reqVO.getIds())
                .orderByDesc(BaseProjectDO::getId));
    }

    default List<BaseProjectDO> selectList(BaseProjectExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseProjectDO>()
                .betweenIfPresent(BaseProjectDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(BaseProjectDO::getProjectName, reqVO.getProjectName())
                .inIfPresent(BaseProjectDO::getId,reqVO.getIds())
                .orderByDesc(BaseProjectDO::getId));
    }

    @Update("UPDATE assets_project SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
